<template>
	<view class="container">
		<!-- 分类导航 -->
		<view class="card mb-20">
			<scroll-view scroll-x class="scroll-x">
				<view class="flex">
					<view class="category-item" :class="{active: activeCategory === index}" v-for="(item, index) in categoryList" :key="index" @click="switchCategory(index)">
						{{ item }}
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 玩乐列表 -->
		<view class="play-list">
			<view class="card mb-20" v-for="(item, index) in playList" :key="index" @click="goToDetail(item)">
				<image :src="item.image" mode="widthFix" style="width: 100%; border-radius: 10rpx;"></image>
				<view class="mt-20">
					<text class="block" style="font-weight: bold; font-size: 32rpx;">{{ item.title }}</text>
					<view class="flex align-center mt-10">
						<text class="text-red">{{ item.score }}分</text>
						<text class="text-gray ml-10">{{ item.comment }}条评论</text>
					</view>
					<text class="block text-gray mt-10">{{ item.address }}</text>
					<view class="flex justify-between mt-20">
						<text class="text-red">¥{{ item.price }}起</text>
						<text class="text-gray">{{ item.distance }}km</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeCategory: 0,
				categoryList: ['全部', '美食', '娱乐', '购物', '休闲', '运动'],
				playList: [
					{
						id: 1,
						title: '全聚德烤鸭店',
						score: 4.5,
						comment: 1280,
						address: '北京市东城区前门大街30号',
						price: 128,
						distance: 1.2,
						image: '/static/food1.jpg'
					},
					{
						id: 2,
						title: '三里屯太古里',
						score: 4.7,
						comment: 2100,
						address: '北京市朝阳区三里屯路19号',
						price: 0,
						distance: 5.5,
						image: '/static/shop1.jpg'
					},
					{
						id: 3,
						title: '798艺术区',
						score: 4.6,
						comment: 960,
						address: '北京市朝阳区酒仙桥路2号',
						price: 50,
						distance: 8.2,
						image: '/static/art1.jpg'
					}
				]
			}
		},
		methods: {
			switchCategory(index) {
				this.activeCategory = index;
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pages/play/detail?id=' + item.id
				})
			}
		}
	}
</script>

<style>
	.scroll-x {
		white-space: nowrap;
		width: 100%;
	}
	
	.category-item {
		display: inline-block;
		padding: 15rpx 30rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		background: #f5f5f5;
	}
	
	.category-item.active {
		background: #4caf50;
		color: #fff;
	}
</style>